using System;
using Avalonia;
using Avalonia.Controls;

namespace AnimationPage.AttachedProperties;

public class ControlProperty
{
    private const string _load = ":loading";
    
    static ControlProperty()
    {
        ValueProperty.Changed.AddClassHandler<Control>(OnHandler);
    }

    public static readonly AttachedProperty<bool> ValueProperty =
        AvaloniaProperty.RegisterAttached<ControlProperty, Control, bool>("Value");

    public static void SetValue(Control obj, bool value) => obj.SetValue(ValueProperty, value);

    public static bool GetValue(Control obj) => obj.GetValue(ValueProperty);
    
    private static bool OnCallback(AvaloniaObject arg1, bool arg2)
    {
        throw new NotImplementedException();
    }

    private static void OnHandler(Control sender, AvaloniaPropertyChangedEventArgs eventArgs)
    {
        var value = eventArgs.GetNewValue<bool>();

        if (sender.Classes is not IPseudoClasses classes)
            return;

        classes.Set(_load, value);
    }
}